package com.itboye.senab.photoview;

import java.util.Observable;
import java.util.Observer;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.config.GlobalConfig;
import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.utils.EnumUtility;
import com.itboye.jmsfhz.R;
import com.itboye.jmsfhz.app.adapter.GridViewAdapter;
import com.itboye.jmsfhz.app.adapter.RoofGridViewAdapter;
import com.itboye.jmsfhz.app.ui.web.WebActivity;
import com.itboye.jmsfhz.data.presenter.Personnelpresenter;
import com.itboye.jmsfhz.data.presenter.Photoersonnelpresenter;
import com.itboye.jmsfhz.widget.MyGridView;
import com.lfh.commentdemo.bean.AppModelNewsBean;

public class PhotoGridview extends BaseActivity implements Observer,OnClickListener {
	private AppModelNewsBean bean;
	Photoersonnelpresenter personnelpresenter;
	int page_num = 1;
	int page_size = 10;
	MyGridView mymygridview;
	RoofGridViewAdapter adapter3;
	TextView txt_title;
	ImageView back;
	Personnelpresenter personnelpresenter2;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_photo_gridview;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		bean = new AppModelNewsBean();
		personnelpresenter2 = new Personnelpresenter(this);
		bean.setPage_num(page_num+"");
		bean.setPage_size(page_size + "");
		bean.setCate(EnumUtility.PHOTO.getValue() + "");
		personnelpresenter2.add(bean);
		txt_title.setText("图片新闻");
		mymygridview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Intent intent = new Intent(PhotoGridview.this, WebActivity.class);
				intent.putExtra("url",
						GlobalConfig.WEBURL + "Webview/Post/viewPost?id="
								+ bean.getList().get(position).getId());
				intent.putExtra("title", "图片新闻");
				bean.setCate(EnumUtility.PHOTO.getValue() + "");
				startActivity(intent);
			}
		});

	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity model = super.handlerError(data);

		if (model.getEventType() == personnelpresenter2.PictureSuccessEvent) {
			bean = (AppModelNewsBean) model.getData();
			adapter3 = new RoofGridViewAdapter(PhotoGridview.this, bean);
			System.out.println(">>>>>>>>>>>>>>>"+model.getData());
			mymygridview.setAdapter(adapter3);
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back:
			this.finish();
			break;

		default:
			break;
		}
	}

}
